﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DI;
using Front.Controllers.Api;
using Core.Dtos;
using Core.Messages;
using StructureMap;
using Core.Queries;
using StructureMap.AutoMocking;
using System.Transactions;
using Tests.Helpers;
using StructureMap.Pipeline;
using Front.Areas.Admin.Controllers.Api;
using CMS.Repositories;
using Library.Logging;

namespace Insurance.Test
{
    [TestClass]
    public class CacheApiControllerTest
    {
        private TransactionScope transScope;
        protected ControllerHelper<CacheApiController> controllerHelper;

        [ClassInitialize()]
        void Initialize()
        {            
        }

        [TestInitialize()]
        public void InitializeTest()
        {
            Bootstrapper.Init(new SingletonLifecycle());
            CurrentContextHelper.Logon();
            transScope = new TransactionScope(TransactionScopeOption.Required);
            controllerHelper = new ControllerHelper<CacheApiController>();
            controllerHelper.Initialize();
        }

        [TestCleanup()]
        public void CleanupTest()
        {
            controllerHelper.Cleanup();
            Bootstrapper.Resolve<AdminDbContext>().Dispose();
            transScope.Dispose();            
        }

        [TestMethod]
        public void CacheApiController_CanFindBy()
        {
            // Arrange            
            var controller = controllerHelper.GetController();                   

            // Act            
            var response = controller.FindBy(CreateQuery());

            // Assert
            Assert.IsNotNull(response);
            Assert.IsTrue(response.List.Count >= 0, "FindBy Failed");
        }

        public CacheQuery CreateQuery()
        {
            return new CacheQuery() { };
        }
    }
}
